package day26;

import java.sql.*;
import java.util.Scanner;

public class Text5 {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement st =null;
        ResultSet rs = null;
        try {
            connection = DBUtil.getConnection();
            Scanner in = new Scanner(System.in);
            System.out.println("姓名");
            String sname = in.next();
            System.out.println("性别");
            String sex = in.next();
            System.out.println("电话");
            String telephone = in.next();
            System.out.println("qq");
            String qq = in.next();
            System.out.println("微信");
            String wechat = in.next();
            System.out.println("年级");
            String gradeid = in.next();
            System.out.println("入学日期");
            String enterdate = in.next();
            System.out.println("家乡");
            String fromcity = in.next();
            System.out.println("生日");
            String birthday = in.next();
            System.out.println("地址");
            String address = in.next();
            String sql = "INSERT INTO `s_student`(sname,sex,telephone,qq,wechat,gradeid,enterdate,fromcity,birthday,address)"
                    + " VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
            st= connection.prepareStatement(sql);
            st.setString(1, sname);
            st.setString(2, sex);
            st.setString(3, telephone);
            st.setString(4, qq);
            st.setString(5, wechat);
            st.setString(6, gradeid);
            st.setString(7, DBUtil.StringToDate(enterdate));
            st.setString(8, fromcity);
            st.setString(9, DBUtil.StringToDate(birthday));
            st.setString(10, address);
            int i = st.executeUpdate();
            if (i == 0) {
                System.out.println("添加失败");
                return;
            }
            System.out.println("添加成功");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            DBUtil.close(rs, st, connection);
        }
    }
}
